package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.FeedbackDto;
import com.huirui.server.pojo.entity.Feedback;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.FeedbackVo;
import com.huirui.server.service.FeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController("adminFeedback")
@RequestMapping("/admin/feedback")
@Slf4j
@Validated
@Tag(name = "反馈管理", description = "微信小程序用户反馈管理")
public class FeedbackController {

    @Resource
    private FeedbackService feedbackService;

    @GetMapping("/list")
    @Operation(summary = "获取用户反馈列表")
    public Result<PageResult<FeedbackVo>> list(
            @Parameter(description = "反馈类型")
            @RequestParam(value = "type", required = false) Integer type,
            @Parameter(description = "处理状态")
            @RequestParam(value = "status", required = false) Integer status,
            @Parameter(description = "反馈提交时间")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            @RequestParam(value = "startTime", required = false) LocalDate startTime,
            @Parameter(description = "反馈提交时间")
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            @RequestParam(value = "endTime", required = false) LocalDate endTime,
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam Long page,
            @RequestParam Long pageSize
    ) {
        PageResult<FeedbackVo> res = feedbackService.listConditional(type, status, startTime, endTime, keyword, page, pageSize);
        return Result.success(res);
    }

    @GetMapping("/detail")
    @Operation(summary = "根据ID获取反馈详情")
    public Result<Feedback> item(@RequestParam Long feedbackId) {
        Feedback one = feedbackService
                .lambdaQuery()
                .eq(Feedback::getId, feedbackId)
                .one();
        return Result.success(one);
    }

    @PostMapping
    @Operation(summary = "更新反馈处理状态")
    public Result<Void> handleFeedback(@RequestBody FeedbackDto feedbackDto) {
        feedbackService.handleFeedback(feedbackDto);
        return Result.success();
    }


}
